#include <a_samp>

// http://de.wikipedia.org/wiki/A*-Algorithmus

stock const bool: FALSE = false;

enum E_aData {
	Float: heuristics,
	Float: distance,
	Float: beeline,
	bool: closed,
	predecessor
}

#define aAlgorithm(%0,%1,%2,%3) for(new aData[sizeof(%1)][E_aData], %0 = ((aAlgorithmMain((%1), (%3), ((%0) = (%2)), aData)) ? (%0) : (-1)); (%0) != -1; (%0) = aData[(%0)][predecessor])

stock aAlgorithmMain(const Points[][], start, const dest, aData[][E_aData], size = sizeof Points) {
	new
		i = 0,
		node = 0,
		next = start,
		Float: dis = 0.0,
		Float: nearest = float(0x7F800000);
	aData[start][predecessor] = -1;
	do {
		if((start = next) == dest) {
			return true;
		}
		for(i = 3; 0 <= Points[start][i]; ++i) {
			node = Points[start][i];
			if((size <= node) || (aData[node][closed])) {
				continue;
			}
			dis = aData[start][distance] + floatpower(floatpower((Float: Points[start][0] - Float: Points[node][0]), 2.0) + floatpower((Float: Points[start][1] - Float: Points[node][1]), 2.0) + floatpower((Float: Points[start][2] - Float: Points[node][2]), 2.0), 0.5);
			if(aData[node][heuristics] == 0.0) {
				aData[node][beeline] = floatpower(floatpower((Float: Points[dest][0] - Float: Points[node][0]), 2.0) + floatpower((Float: Points[dest][1] - Float: Points[node][1]), 2.0) + floatpower((Float: Points[dest][2] - Float: Points[node][2]), 2.0), 0.5);
			} else {
				if(aData[node][distance] <= dis) {
					continue;
				}
			}
			aData[node][heuristics] = dis + aData[node][beeline];
			aData[node][predecessor] = start;
			aData[node][distance] = dis;
			if(aData[node][heuristics] < nearest) {
				nearest = aData[node][heuristics];
				next = node;
			}
		}
		aData[start][closed] = true;
		if(start == next) {
			for(i = 0, nearest = float(0x7F800000); i != size; ++i) {
				if((aData[i][closed] == false) && (aData[i][heuristics] != 0.0)) {
					if(aData[i][heuristics] < nearest) {
						nearest = aData[i][heuristics];
						next = i;
					}
				}
			}
		}
	} while(start != next);
	return false;
}

public OnFilterScriptInit() {
	#define points{%0,%1,%2,%3} {_:%0,_:%1,_:%2,%3,-1}

	new const aPoints[][] = {
		points{ -2427.62, -2474.75, 35.75, 106, 6 },
		points{ -2350.25, -2575.62, 44.75, 37, 2 },
		points{ -2365.87, -2564.62, 43.87, 1, 3 },
		points{ -2379.75, -2552.62, 42.87, 2, 4 },
		points{ -2391.87, -2539.00, 41.87, 3, 5 },
		points{ -2402.00, -2524.75, 40.75, 4, 6 },
		points{ -2411.25, -2508.87, 39.25, 0, 5 },
		points{ -2513.75, -2666.75, 40.00, 18, 16 },
		points{ -2565.37, -2520.12, 21.50, 46, 9 },
		points{ -2558.25, -2545.12, 25.25, 8, 10 },
		points{ -2555.12, -2566.50, 27.50, 9, 11 },
		points{ -2551.62, -2586.25, 29.12, 10, 12 },
		points{ -2547.37, -2604.37, 31.00, 11, 13 },
		points{ -2542.50, -2620.75, 33.00, 12, 14 },
		points{ -2536.75, -2635.12, 34.87, 13, 15 },
		points{ -2530.25, -2647.62, 36.75, 14, 16 },
		points{ -2522.50, -2658.25, 38.87, 7, 15 },
		points{ -2397.50, -2682.50, 45.75, 146, 24 },
		points{ -2492.50, -2677.12, 42.25, 7, 19 },
		points{ -2479.62, -2679.00, 43.12, 18, 20 },
		points{ -2465.50, -2678.37, 43.62, 19, 21 },
		points{ -2449.62, -2675.25, 43.75, 20, 22 },
		points{ -2440.75, -2674.00, 44.00, 21, 23 },
		points{ -2431.00, -2674.25, 44.50, 22, 24 },
		points{ -2409.37, -2678.50, 45.75, 17, 23 },
		points{ -2313.50, -2719.25, 43.25, 145, 149, 142 },
		points{ -2284.00, -2625.25, 35.25, 141, 27 },
		points{ -2271.12, -2586.62, 32.12, 26, 28 },
		points{ -2260.00, -2560.00, 30.87, 27, 29 },
		points{ -2250.12, -2543.50, 30.75, 28, 8 },
		points{ -2386.00, -2599.12, 56.00, 40, 31 },
		points{ -2399.62, -2591.12, 55.00, 30, 32 },
		points{ -2412.75, -2582.25, 53.62, 31, 33 },
		points{ -2424.75, -2572.62, 52.25, 32, 36 },
		points{ -2450.12, -2541.00, 48.00, 64, 35 },
		points{ -2443.87, -2551.75, 49.25, 34, 36 },
		points{ -2435.37, -2562.37, 50.75, 33, 35 },
		points{ -2313.37, -2595.75, 46.37, 1, 38 },
		points{ -2292.00, -2605.75, 46.75, 37, 39 },
		points{ -2268.25, -2616.00, 47.00, 38, 68 },
		points{ -2340.00, -2620.50, 58.00, 30, 41 },
		points{ -2312.62, -2633.12, 58.37, 40, 42 },
		points{ -2266.25, -2654.12, 57.87, 41, 87 },
		points{ -2499.12, -2303.25, 13.87, 63, 44 },
		points{ -2484.50, -2301.75, 13.87, 43, 45 },
		points{ -2469.87, -2299.75, 14.00, 102, 44 },
		points{ -2600.12, -2455.62, 17.12, 8, 48 },
		points{ -2617.12, -2345.25, 10.75, 197, 50 },
		points{ -2619.12, -2423.12, 16.00, 46, 49 },
		points{ -2627.25, -2390.25, 14.25, 48, 50 },
		points{ -2625.37, -2359.62, 11.87, 47, 49 },
		points{ -2345.25, -2251.12, 16.50, 184, 315, 56, 127 },
		points{ -2359.25, -2257.75, 15.00, 55, 56 },
		points{ -2398.00, -2275.87, 13.75, 104, 54 },
		points{ -2382.25, -2268.50, 13.62, 53, 55 },
		points{ -2365.50, -2260.62, 14.37, 52, 54 },
		points{ -2352.37, -2254.50, 15.75, 51, 52 },
		points{ -2560.00, -2272.00, 15.25, 62, 59 },
		points{ -2560.00, -2256.25, 19.25, 59, 330 },
		points{ -2560.00, -2264.87, 16.62, 57, 58 },
		points{ -2559.62, -2305.75, 13.00, 198, 63, 61 },
		points{ -2560.00, -2290.00, 13.25, 60, 62 },
		points{ -2560.00, -2284.75, 13.62, 57, 61 },
		points{ -2538.25, -2305.12, 14.12, 43, 60, 75 },
		points{ -2458.00, -2520.12, 45.50, 34, 82, 66 },
		points{ -2532.62, -2389.12, 15.12, 76, 74 },
		points{ -2475.75, -2499.00, 41.62, 64, 67 },
		points{ -2483.62, -2487.25, 39.25, 66, 68 },
		points{ -2489.12, -2478.12, 37.25, 67, 69 },
		points{ -2495.62, -2467.12, 34.25, 68, 70 },
		points{ -2503.00, -2454.75, 30.50, 69, 71 },
		points{ -2510.12, -2442.12, 26.62, 70, 72 },
		points{ -2520.50, -2423.62, 21.12, 71, 73 },
		points{ -2525.75, -2412.62, 18.37, 72, 74 },
		points{ -2529.50, -2401.50, 16.37, 65, 73 },
		points{ -2538.25, -2322.12, 13.62, 63, 80 },
		points{ -2535.50, -2366.75, 14.00, 65, 77 },
		points{ -2536.75, -2356.00, 13.62, 76, 78 },
		points{ -2537.50, -2344.25, 13.37, 77, 79 },
		points{ -2537.62, -2336.62, 13.37, 78, 80 },
		points{ -2538.00, -2329.62, 13.37, 75, 79 },
		points{ -2492.00, -2391.62, 29.87, 92, 90 },
		points{ -2466.75, -2490.12, 41.00, 64, 83 },
		points{ -2470.37, -2475.50, 38.75, 82, 84 },
		points{ -2473.50, -2463.00, 36.75, 83, 85 },
		points{ -2475.37, -2454.25, 35.50, 84, 86 },
		points{ -2477.62, -2445.00, 34.50, 85, 87 },
		points{ -2479.50, -2436.25, 33.25, 86, 88 },
		points{ -2482.62, -2425.00, 32.25, 87, 89 },
		points{ -2484.50, -2418.00, 31.62, 88, 90 },
		points{ -2489.50, -2400.87, 30.50, 81, 89 },
		points{ -2521.62, -2278.25, 28.00, 101, 100 },
		points{ -2497.75, -2369.75, 28.75, 81, 93 },
		points{ -2500.75, -2358.12, 28.37, 92, 94 },
		points{ -2502.87, -2349.75, 28.00, 93, 95 },
		points{ -2506.50, -2336.62, 28.00, 94, 96 },
		points{ -2509.50, -2324.62, 28.00, 95, 97 },
		points{ -2511.50, -2316.75, 28.00, 96, 98 },
		points{ -2514.37, -2306.00, 28.00, 97, 99 },
		points{ -2516.62, -2297.25, 28.00, 98, 100 },
		points{ -2519.25, -2287.37, 28.00, 91, 99 },
		points{ -2527.25, -2256.50, 28.00, 91, 332 },
		points{ -2448.12, -2295.00, 13.50, 45, 105, 109 },
		points{ -2426.62, -2288.37, 13.12, 105, 104, 113 },
		points{ -2416.00, -2283.87, 13.37, 53, 103 },
		points{ -2438.50, -2292.37, 13.25, 102, 103 },
		points{ -2445.00, -2433.12, 32.25, 0, 108, 136 },
		points{ -2460.50, -2391.87, 29.87, 117, 108 },
		points{ -2456.87, -2402.25, 30.50, 106, 107 },
		points{ -2445.12, -2308.00, 13.87, 102, 112 },
		points{ -2442.50, -2326.25, 15.87, 135, 111 },
		points{ -2443.25, -2319.12, 14.75, 110, 112 },
		points{ -2444.00, -2315.00, 14.37, 109, 111 },
		points{ -2433.87, -2270.25, 13.37, 103, 114 },
		points{ -2438.00, -2261.62, 14.00, 113, 115 },
		points{ -2444.37, -2252.50, 15.50, 114, 338 },
		points{ -2494.25, -2259.62, 28.00, 344, 122 },
		points{ -2470.00, -2359.25, 28.50, 107, 118 },
		points{ -2473.87, -2344.62, 28.12, 117, 119 },
		points{ -2478.75, -2327.25, 28.00, 118, 120 },
		points{ -2481.62, -2314.50, 28.00, 119, 121 },
		points{ -2485.62, -2296.87, 28.00, 120, 122 },
		points{ -2490.50, -2275.00, 28.00, 116, 121 },
		points{ -2288.00, -2308.12, 24.00, 126, 125 },
		points{ -2260.00, -2322.87, 27.87, 125, 348 },
		points{ -2276.50, -2314.25, 25.62, 123, 124 },
		points{ -2296.75, -2303.25, 23.00, 123, 134 },
		points{ -2341.12, -2257.87, 17.00, 51, 128 },
		points{ -2339.50, -2260.50, 17.00, 127, 129 },
		points{ -2334.50, -2267.25, 18.00, 128, 130 },
		points{ -2330.12, -2273.00, 19.50, 129, 131 },
		points{ -2324.50, -2280.50, 20.00, 130, 132 },
		points{ -2318.25, -2289.00, 20.87, 131, 133 },
		points{ -2311.87, -2294.75, 21.62, 132, 134 },
		points{ -2304.37, -2299.00, 22.25, 126, 133 },
		points{ -2441.87, -2338.12, 18.00, 110, 140 },
		points{ -2444.00, -2400.25, 30.50, 106, 137 },
		points{ -2442.87, -2386.00, 29.25, 136, 138 },
		points{ -2442.00, -2369.25, 26.37, 137, 139 },
		points{ -2441.50, -2358.00, 23.37, 138, 140 },
		points{ -2441.62, -2346.50, 19.87, 135, 139 },
		points{ -2297.50, -2670.62, 39.25, 26, 144 },
		points{ -2308.00, -2708.50, 43.25, 25, 143 },
		points{ -2305.25, -2697.50, 42.00, 142, 144 },
		points{ -2300.75, -2681.87, 40.50, 141, 143 },
		points{ -2332.87, -2710.25, 43.75, 25, 148 },
		points{ -2366.00, -2695.50, 45.75, 17, 147 },
		points{ -2357.87, -2699.25, 45.50, 146, 148 },
		points{ -2343.50, -2706.00, 44.50, 145, 147 },
		points{ -2296.12, -2727.75, 42.25, 25, 151 },
		points{ -2271.12, -2739.00, 39.50, 152, 151 },
		points{ -2281.62, -2734.50, 40.50, 149, 150 },
		points{ -2261.87, -2742.62, 38.50, 150, 356 },
		points{ -2291.50, -2767.62, 16.25, 160, 154 },
		points{ -2284.00, -2770.62, 18.75, 153, 155 },
		points{ -2275.62, -2773.87, 20.75, 154, 156 },
		points{ -2264.50, -2777.25, 22.75, 155, 358 },
		points{ -2446.25, -2733.25, 5.25, 168, 166 },
		points{ -2340.12, -2764.50, 11.50, 159, 161 },
		points{ -2325.25, -2766.62, 12.37, 158, 160 },
		points{ -2315.62, -2766.75, 13.50, 153, 159 },
		points{ -2351.50, -2761.75, 11.50, 158, 162 },
		points{ -2371.25, -2754.50, 7.12, 161, 163 },
		points{ -2382.00, -2753.50, 6.25, 162, 164 },
		points{ -2399.12, -2752.12, 5.12, 163, 165 },
		points{ -2408.50, -2749.12, 5.00, 164, 166 },
		points{ -2428.75, -2741.75, 5.25, 157, 165 },
		points{ -2554.12, -2687.50, 7.50, 178, 176 },
		points{ -2465.75, -2725.00, 7.25, 157, 169 },
		points{ -2476.62, -2724.00, 11.37, 168, 170 },
		points{ -2486.50, -2723.12, 13.00, 169, 171 },
		points{ -2503.37, -2724.50, 12.87, 170, 172 },
		points{ -2509.25, -2724.00, 14.37, 171, 173 },
		points{ -2517.50, -2721.25, 14.75, 172, 174 },
		points{ -2531.50, -2715.87, 13.62, 173, 175 },
		points{ -2538.62, -2706.00, 11.75, 174, 176 },
		points{ -2544.12, -2698.87, 9.62, 167, 175 },
		points{ -2620.12, -2515.00, 2.75, 188, 186 },
		points{ -2572.75, -2660.75, 7.00, 167, 179 },
		points{ -2578.00, -2648.12, 10.37, 178, 180 },
		points{ -2584.25, -2633.75, 9.75, 179, 181 },
		points{ -2589.12, -2616.00, 7.00, 180, 182 },
		points{ -2594.25, -2597.37, 2.12, 181, 183 },
		points{ -2602.87, -2581.62, 2.00, 182, 184 },
		points{ -2606.25, -2566.50, 1.87, 183, 185 },
		points{ -2608.00, -2548.50, 2.00, 184, 186 },
		points{ -2613.75, -2530.87, 1.87, 177, 185 },
		points{ -2662.37, -2347.87, 2.00, 203, 196 },
		points{ -2630.25, -2495.00, 8.50, 177, 189 },
		points{ -2633.75, -2488.75, 10.00, 188, 190 },
		points{ -2639.25, -2480.12, 8.37, 189, 191 },
		points{ -2648.75, -2463.37, 5.00, 190, 192 },
		points{ -2654.75, -2449.75, 3.62, 191, 193 },
		points{ -2659.50, -2428.50, 2.25, 192, 194 },
		points{ -2665.62, -2408.00, 2.00, 193, 195 },
		points{ -2665.75, -2387.25, 1.87, 194, 196 },
		points{ -2665.50, -2365.37, 2.00, 187, 195 },
		points{ -2603.12, -2327.25, 10.12, 47, 202, 199 },
		points{ -2573.75, -2308.25, 11.87, 60, 201 },
		points{ -2594.00, -2318.00, 10.12, 197, 200 },
		points{ -2588.00, -2314.12, 10.62, 199, 201 },
		points{ -2581.50, -2310.25, 11.25, 198, 200 },
		points{ -2614.00, -2313.87, 9.87, 197, 208 },
		points{ -2655.37, -2323.00, 4.12, 187, 204 },
		points{ -2648.87, -2309.00, 5.87, 203, 205 },
		points{ -2638.25, -2302.00, 6.87, 204, 206 },
		points{ -2630.25, -2300.87, 7.87, 205, 207 },
		points{ -2622.00, -2304.75, 8.62, 206, 208 },
		points{ -2618.50, -2309.25, 8.62, 202, 207 }
	};

	aAlgorithm(node, aPoints, random(sizeof aPoints), random(sizeof aPoints)) {
		printf("%d", node);
	}
}